#include "mockcpp/mockcpp.hpp"
#include "pub.h"
#include "routes_api.h"
#include "gtest/gtest.h"
#include <iostream>
#include <stdio.h>

// setuptestcase fixture
// setup everycase

extern "C" {
// for c declare of global varible
}

class RoutesTest : public ::testing::Test {
  protected:
    virtual void SetUp() { std::cout << "setup executor" << std::endl; }
    virtual void TearDown()
    {
        std::cout << "teardown executor" << std::endl;
        GlobalMockObject::verify();
    }
    static void SetUpTestCase() { std::cout << "setup by case" << std::endl; }
    static void TearDownTestCase()
    {
        std::cout << "teardown by case" << std::endl;
    }
};

BEST_STATUS FakeCallback(BEST_UINT32 *msgHdr, BEST_UINT32 msgLen)
{
    return BEST_OK;
}

TEST_F(RoutesTest, InitMsgAndSndMsg)
{
    // MOCKER(printf).stubs().expects(once());
    // MOCKER(HandleFuncOfLazyExec).expects(once());
    ASSERT_EQ(RoutesInit(), BEST_OK);

    // MOCKER(FakeCallback).stubs().with(any(),
    // any()).will(returnValue(BEST_OK));
    ASSERT_EQ(RoutesRegMsgCallback(E_ROUTES_CB_A, FakeCallback), BEST_OK);
    ASSERT_EQ(RoutesSendMsg(E_ROUTES_CB_A, nullptr, 0), BEST_OK);
}

TEST_F(RoutesTest, InitMsgAndSndMsgAndGetMsg)
{
    ASSERT_EQ(RoutesInit(), BEST_OK);
    ASSERT_EQ(RoutesRegMsgCallback(E_ROUTES_CB_A, FakeCallback), BEST_OK);
    MOCKER(FakeCallback).stubs().with(any(), any()).will(returnValue(BEST_ERR));
    ASSERT_EQ(RoutesSendMsg(E_ROUTES_CB_A, nullptr, 0), BEST_ERR);
}

TEST_F(RoutesTest, InitMsgAndUnRegRoutedAndSndMsgAndGetMsg)
{
    ASSERT_EQ(RoutesInit(), BEST_OK);
    ASSERT_EQ(RoutesRegMsgCallback(E_ROUTES_CB_A, FakeCallback), BEST_OK);
    MOCKER(FakeCallback).stubs().with(any(), any()).will(returnValue(BEST_ERR));
    ASSERT_EQ(RoutesSendMsg(E_ROUTES_CB_A, nullptr, 0), BEST_ERR);
    ASSERT_EQ(RoutesUnRegMsgCallback(E_ROUTES_CB_A), BEST_OK);
    MOCKER(FakeCallback).stubs().with(any(), any()).will(returnValue(BEST_ERR));
    ASSERT_EQ(RoutesSendMsg(E_ROUTES_CB_A, nullptr, 0), BEST_ERR);
}